<?php 
namespace Home\Model;
use \Think\Model;


class ReplyModel extends Model
{
    public function getReply()
    {
        import('ORG.Util.Page');
        $count = M('reply')->where('tid='.$_GET['t'])->count();
        $page = new \Think\Page($count,3);
        $show = $page->show();
        // $data = M('admin')->order('id')->limit($page->firstRow.','.$page->listRows)->select();

        $reply = $this->field('uid,content,time,floor,rid')->order('floor')->limit($page->firstRow.','.$page->listRows)->where('tid='.$_GET['t'])->select();
        // var_dump($list);
        foreach ($reply as $key => $value) {
            $user_info = $this->table('dota2_user u,dota2_user_info ui')->field('icon,nickname,email')->where('u.u_id=ui.ui_id and ui_id='.$value['uid'])->find();
            if (!empty($user_info['icon'])) {
                $icon = '/Uploads/person_icon/';
                $icon .= substr($user_info['icon'],0,8).'/'.$user_info['icon'];
            }else{$icon=null;}
            $rid = M('reply')->field('rid')->where('floor='.$reply[$key]['floor'].' and tid = '.$_GET['t'])->select()[0]['rid'];
            // var_dump($rid);
            $reply[$key]['icon'] = $icon;
            $reply[$key]['nickname'] = $user_info['nickname'];
            $reply[$key]['email'] = $user_info['email'];

            $reply_floor = $this->table('dota2_reply_floor')->field('uid,content,time')->where('rid='.$rid.' and tid='.$_GET["t"])->select();
            // var_dump($reply_floor);
            foreach ($reply_floor as $k => $v) {
                $user_info2 = $this->table('dota2_user u,dota2_user_info ui')->field('icon,nickname,email')->where('u.u_id=ui.ui_id and ui_id='.$v['uid'])->find();
                if (!empty($user_info2['icon'])) {
                    $icon2 = '/Uploads/person_icon/';
                    $icon2 .= substr($user_info2['icon'],0,8).'/'.$user_info2['icon'];
                }else{$icon2=null;}
                $reply_floor[$k]['icon'] = $icon2;
                $reply_floor[$k]['nickname'] = $user_info2['nickname'];
                $reply_floor[$k]['email'] = $user_info2['email'];
            }
            $reply[$key]['reply_floor']=$reply_floor;
        }
        $list['reply'] = $reply;
        $list['page'] = $show;
        return $list;
    }

}


